import 'package:flutter/material.dart';
import 'package:kq_flutter_tv_widgets/widgets/button/kq_small_button.dart';
import 'package:kq_flutter_tv_widgets/widgets/popupWindow/popup_window.dart';

/// PopupWindowDemo
class PopupWindowDemo extends StatefulWidget {
  const PopupWindowDemo({super.key});

  @override
  State<StatefulWidget> createState() => _PopupWindowDemoState();
}

class _PopupWindowDemoState extends State<PopupWindowDemo> {
  PopupWindowController controller = PopupWindowController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PopupWindow(
        controller: controller,
        buildPopup: (controller) {
          return Container(
            color: Colors.red,
            child: Align(
              child: Container(
                alignment: Alignment.center,
                width: 50,
                height: 30,
                child: KqSmallButton(
                  title: '关闭',
                  onTap: (d) {
                    controller.close();
                  },
                ),
              ),
            ),
          );
        },
        child: TestWindow(
          controller: controller,
        ),
      ),
    );
  }
}

class TestWindow extends StatelessWidget {
  final PopupWindowController controller;

  const TestWindow({super.key, required this.controller});

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.amberAccent,
      child: KqSmallButton(
        title: "打开弹窗",
        onTap: (d) {
          controller.open();
        },
      ),
    );
  }
}
